﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Sauces.Bussinees.Entities.Caja;
using Sauces.Bussinees.Logic.Caja.Service;
using Microsoft.Practices.Unity;
using System.Web.ModelBinding;

namespace Sauces.Web.Caja
{
    public partial class FrmCliente : System.Web.UI.Page
    {
        [Dependency]
        public IClienteService clienteService { set; get; }
        protected void Page_Load(object sender, EventArgs e)
        {
            var accion = Request.QueryString["action"];
            var IdCliente = Request.QueryString["IdCliente"];

            if (accion != null && accion == "new")
            {
                fvCliente.DefaultMode = FormViewMode.Insert;
            }
            else if (accion != null && IdCliente != null && accion == "delete")
            {
                var id = Int32.Parse(IdCliente.ToString());

                clienteService.removeCliente(id);
                Response.Redirect("FrmListaCliente.aspx");
            }

            

        }

        public Cliente getClienteByid([QueryString("IdCliente")]Int32? id)
        {
            if (id.HasValue)
            {
                return clienteService.getFromClienteById(id.Value);
            }
            return null;
        }

        public void UpdateCliente(Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                clienteService.upDateCliente(cliente);
                Response.Redirect("FrmListaCliente.aspx");
            }
        }

        public void AddCliente(Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                clienteService.addCliente(cliente);
                Response.Redirect("FrmListaCliente.aspx");
            }
        }

        protected void rbNatural_CheckedChanged(object sender, EventArgs e)
        {
            
        }

       
               

    }
}